package client;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

import server.Server;
import static debug.Debug.DBUG;

public class ClientListener implements Runnable {

	private ServerSocket sock;
	private Server server;
	
	public ClientListener(Server serv) {
		server = serv;
		try {
			sock = new ServerSocket(4343);
		} catch (IOException e) {
			DBUG("failed to get serversocket");
		}
		new Thread(this).start();
	}
	
	public void run() {
		while (true) {
			try {
				Socket connection = sock.accept();
				new ClientControl(connection, server);
			} catch (IOException e) {
				DBUG("Failed sock.accept()");
			}
			DBUG("accepted a connection");
		}
	}
}
